Repository navigation
CORS: add Vary: Origin when the answer depends on the origin, warn on '*' with credentials, add an origin matcher - #1613
Merged
Merged
Conversation
… '*' with credentials, add an origin matcher - Vary: Origin is added when the CORS answer depends on the request origin (origin allow-list or credentials), including for requests without Origin; a static '*' without credentials sends no Vary (Fetch standard). - A warning is logged when '*' is allowed together with credentials. - Optional origin matcher (setAllowedOriginMatcher), off by default. - Javadoc references the Fetch standard instead of the W3C CORS draft. Refs #1611 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



The aim
Refs #1611
Make CORS safe behind shared caches and with credentials, following the Fetch standard (CORS protocol, "CORS protocol and HTTP caches") and RFC 9110 section 12.5.5.
Vary: Originwas never sent, so a shared cache could serve the response built for one origin to another, or serve a response without CORS headers to a CORS request.*allowed together with credentials makes the filter echo any request origin withAccess-Control-Allow-Credentials: true.*) can be allowed.The solution
CorsResponseHelper:Vary: Originis added on every response when the answer depends on the origin (credentials, or allowed origins without*), including requests withoutOrigin. A static*without credentials sends noVary, as recommended by Fetch.CorsFilter: logs a warning when*is allowed with credentials (behaviour unchanged in 2.7; 3.0 rejects it).setAllowedOriginMatcher(Predicate<String>)onCorsService,CorsFilterandCorsResponseHelper(default none). The response always carries the exact request origin. Only effective when the allowed origins don't contain*.Reproduction
curl -i -H 'Origin: https://a.example' <url>withCorsService.setAllowedOrigins({"https://a.example"}): the response now hasVary: Origin, also without theOriginheader.Check-list
Companion PR for 3.0, where
*with credentials is rejected.🤖 Generated with Claude Code